﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace L03
{
    #region T1
    public class LinkNode<T>
    {
        private T data;
        private LinkNode<T> next;

        public T Data { get => Data; set => Data = value; }
        public LinkNode<T> Next { get => Next; set => Next = value; }
        public LinkNode()
        {
            this.data = default(T);
            this.next = null;
        }

        public LinkNode(T t)
        {
            this.Data = t;
            this.Next = null;
        }

        public LinkNode(T t, LinkNode<T> node)
        {
            this.Data = t;
            this.Next = node;
        }

}

    public class LinkList<T>:ILinkable<T>
    {
        private LinkNode<T> first;

        public LinkNode<T> First { get => first; set => first = value; }

        public LinkList()
        {
            this.first = null;
        }

        public LinkList(LinkNode<T> node)
        {
            this.first= node;
        }

        bool ILinkable<T>.IsEmpty()
        {
            return this.first == null;
        }

        public int Count
        {
            get
            {
                int i = 0;
                LinkNode<T> node = first;
                while (node!= null)
                {
                    node = node.Next;
                    i++;
                }
                return i;
            }
        }

        public LinkNode<T> GetNode(int pos)
        {
            LinkNode<T> node = first; for (int i = 0; i < pos; i++)
            {
                if (node.Next == null)
                {
                    throw new IndexOutOfRangeException();
                }
                node = node.Next;
            }
            return node;
        }
    }

    public interface ILinkable<T>
    {
        bool IsEmpty();
    }

    #endregion

    class Program
    {
        static void Main(string[] args)
        {
            #region T1
            LinkList<int> MyList = new LinkList<int>();
            LinkNode<int> node = new LinkNode<int>();
            Console.WriteLine("{0}", MyList.Count);
            #endregion

            #region T2
            Dictionary<string, string> dic1 = new Dictionary<string, string>();

            dic1.Add("星期一", "Monday");
            dic1.Add("星期二", "Tuesday");
            dic1.Add("星期三", "Wednesday");
            dic1.Add("星期四", "Thursday");
            dic1.Add("星期五", "Friday");
            dic1.Add("星期六", "Saturday");
            dic1.Add("星期七", "Sunday");

            if (dic1.ContainsKey("星期一"))
            {
                Console.WriteLine("Key:{0},Value:{1}", "星期一", dic1["星期一"]);
            }

            Dictionary<int, Tuple<String, String>> dic2 = new Dictionary<int, Tuple<String, String>>();
            dic2.Add(1, new Tuple<string, string>("a", "b"));
            dic2.Add(2, new Tuple<string, string>("b", "c"));
            dic2.Add(3, new Tuple<string, string>("c", "d"));

            if (dic2.ContainsKey(2))
            {
                Console.WriteLine("Key:{0},Value:{1}", "2", dic2[2]);
            }

            foreach (KeyValuePair<string, string> dic in dic1)
            {
                Console.WriteLine("\t{0}\t{1}", dic.Key, dic.Value);
            }

            foreach (KeyValuePair<int,Tuple<string,string>> dic in dic2)
            {
                Console.WriteLine("\t{0}\t{1}", dic.Key, dic.Value);
            }

            #endregion


            Console.ReadKey();
        }

        
    }
}
